<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        var arr = [1,5,4,5,4,8,1,5,1,5];

        for( var j=0;j<arr.length-1;j++ ){
            for( var i=0;i<arr.length-1-j;i++ ){
                if( arr[i]>arr[i+1] ){
                    var temp = arr[i];
                    arr[i] = arr[i+1];
                    arr[i+1] = temp;
                }
               
            }
        }
        //原理就是里面的循环是把最大的一个数放到最后(只是排序一次);外面的循环则是完全循环最大的数放在最后面,一直排好;
        console.log(arr);//[1, 1, 1, 4, 4, 5, 5, 5, 5, 8]
    </script>
</body>
</html>